import msgpack

class Shape:

    def __init__(self,a,h,r):
        self.a = a
        self.h = h
        self.r = r
        self.PI = 3.14

    def triangle_s(self):
        S = msgpack.dumps(1/2 * self.a * self.h)
        return S
    def rectangle_s(self):
        S = msgpack.dumps(self.a * self.h)
        return S
    def circular_s(self):
        S = msgpack.dumps(self.PI * self.r ** 2)
        return S

class Triangle(Shape):pass
class Rectangle(Shape):pass
class Circular(Shape):pass

t = Triangle(2,3,4)
r = Rectangle(2,3,4)
c = Circular(2,3,4)
print(c.circular_s())
print(t.triangle_s())
print(r.rectangle_s())


#改进
class Shape:

    def __init__(self,a,h,r):
        self.a = a
        self.h = h
        self.r = r
        self.PI = 3.14

class Triangle(Shape):
    def triangle_s(self):
        #super().__init__()
        S = msgpack.dumps(1/2 * self.a * self.h)
        return S

class Rectangle(Shape):
    def rectangle_s(self):
        #super().__init__()
        S = msgpack.dumps(self.a * self.h)
        return S

class Circular(Shape):
    def circular_s(self):
        #super().__init__()
        S = msgpack.dumps(self.PI * self.r ** 2)
        return S

t = Triangle(2,3,4)
r = Rectangle(2,3,4)
c = Circular(2,3,4)
print(c.circular_s())
print(t.triangle_s())
print(r.rectangle_s())


# Shape类里面为什么初始化要传3个参数呢，为什么要初始化一个PI变量出来呢，再说变量的话，一般都是小写字母，大写字母一般都是常量或和配置相关的信息
